<?php


namespace app\admin\controller\setting;


use app\admin\controller\AdminController;
use app\admin\service\setting\DbRedisService;
use app\admin\validate\setting\DbRedisValidate;
use think\response\Json;

class DbRedis extends AdminController
{
    /**
     * 获取redis信息
     * @return Json
     */
    public function info()
    {
        $params = $this->getData();
        return $this->success(DbRedisService::info($params));
    }

    /**
     * 缓存详情
     * @return Json
     */
    public function detail()
    {
        $params = (new DbRedisValidate())->checkParam('detail');
        $result = DbRedisService::detail($params);
        return $this->data($result);
    }

    /**
     * 编辑缓存
     * @return Json
     */
    public function edit()
    {
        $params = (new DbRedisValidate())->post()->checkParam('edit');
        $result =  DbRedisService::edit($params);
        if(true === $result) {
            return $this->success([], '编辑成功');
        } else {
            return $this->error(DbRedisService::getError());
        }
    }

    /**
     * 删除缓存
     * @return Json
     */
    public function delete()
    {
        $params = (new DbRedisValidate())->delete()->checkParam('delete');
        $result =  DbRedisService::delete($params);
        if(true === $result) {
            return $this->success([], '删除成功');
        } else {
            return $this->error(DbRedisService::getError('删除失败'));
        }
    }
}